home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / bbs / utilz20x.zip / GODIR / GODIR.CPP next >
C/C++ Source or Header  |  1997-04-13  |  2KB  |  74 lines

  1. /*
  2.  * This file is part of Utiliteez v1.00.R1
  3.  *
  4.  * Copyright (c) 1995, 1997 by Branislav L. Slantchev
  5.  * A fine product of Silicon Creations, Inc. (gargoyle)
  6.  *
  7.  * This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; either version 2 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but without any warranty; without even the implied warranty of
  14.  * merchantability or fitness for a particular purpose. See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the License along with this
  18.  * library, in the file LICENSE.DOC; if not, write to the address
  19.  * below to receive a copy via electronic mail.
  20.  *
  21.  * You can reach Branislav L. Slantchev (Silicon Creations, Inc.)
  22.  * at bslantch@cs.angelo.edu. The file SUPPORT.DOC has the current
  23.  * telephone numbers and the postal address for contacts.
  24. */
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include <ctype.h>
  28. #include <direct.h>
  29. #include "file.h"
  30. #include "utils.h"
  31.  
  32.     int
  33. main(int argc, char **argv)
  34. {
  35.     char  path[81];
  36.     char *token, *progname;
  37.     FILE *fp;
  38.  
  39.     progname = file_name(strlwr(*argv));
  40.     if( 1 == argc ) fail( "usage: %s keyword <data file>", progname);
  41.     token = argv[1];
  42.  
  43.     if( 3 == argc ) strcpy(path, argv[2]);
  44.     else strcpy(path, strcat(file_dirspec(*argv), "godir.dat"));
  45.  
  46.     if( NULL == (fp = fopen(path, "r")) )
  47.         fail( "%s: couldn't find data file '%s'", progname, path );
  48.  
  49.     for( ;; )
  50.     {
  51.         char  buf[255];
  52.         char *p;
  53.  
  54.         fgets( buf, sizeof(buf), fp );
  55.         if( feof(fp) ) fail("%s: unable to find '%s'", progname, token);
  56.  
  57.         if( '#' == buf[0] || NULL == (p = strtok(buf, " \t")) ) continue;
  58.  
  59.         if( 0 == stricmp(p, token) )
  60.         {
  61.             if( NULL == (p = strtok(NULL, " \t\n")) )
  62.                 fail("%s: path not defined for '%s'", progname, token);
  63.             if( 0 != _chdrive(toupper(*p) - '@') )
  64.                 fail("%s: drive not ready - '%s:'", progname, *p);
  65.             if( -1 == file_chdir(p) )
  66.                 fail("%s: invalid path '%s'", progname, p);
  67.             break;
  68.         }
  69.     }
  70.  
  71.     fclose(fp);
  72.     return 0;
  73. }
  74.